<?php
namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Api\BaseController;
use App\Http\Resources\Message;
use App\Http\Resources\MessageCollection;
use App\Message as MessageModel;
use App\Repositories\MessageRepository;
use App\Scopes\StatusScope;
use App\Traits\BaseApiFunc;
use Illuminate\Database\Eloquent\Collection;

class MessageController extends BaseController {

	use BaseApiFunc;

	protected $model, $page_size;

	public function __construct(MessageRepository $message) {
		parent::__construct();

		$this->model = $message;
		$this->page_size = config('blog.admin_page.common_page');
	}

	protected function getResourceCollection(Collection $collection) {
		return new MessageCollection($collection->load(['user' => function ($query) {
			return $query->withoutGlobalScope(StatusScope::class);
		}]));
	}

	protected function getResource(MessageModel $collection) {
		return new Message($collection);
	}
}
